<%
' +----------------------------------------------------------------------
' | POPASP [ ASP MVC ]
' +----------------------------------------------------------------------
' | Copyright (c) 2016 http://popasp.com All rights reserved.
' +----------------------------------------------------------------------
' | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
' +----------------------------------------------------------------------
' | Author: popasp <1737025626@qq.com>
' +----------------------------------------------------------------------
Class POPASP_APPLICATION
	Private prefix
	
	Public Sub Export
		Dim x,i : i=1
		for each x in Application.Contents
			Response.Write( "Index: " & i  & ","&  x & "=" & Application.Contents(x) & "<br />")
			i = i+1
		next
	End Sub
	
	' 清空所有 Application.Contents
	Public Sub Clear()
		Application.Contents.RemoveAll
	End Sub
	
	' 清除前缀为prefix的那一部分
	Public Sub RemoveAll
		dim key,l
		if prefix = "" Then
			Clear
		Else
			l = Len(prefix)
			For Each key in Application.Contents
				if Left(key,l) = prefix Then
					Remove key
				End If
			Next 
		End If
	End Sub
	
	' 清除某一个键值对
	Public Sub Remove(key)
		key = getKey(key)
		Application.Contents.Remove key
	End Sub
	
	' 某个键是否存在
	Public Function Exists(key)
		key = getKey(key)
		Exists =  (Not isEmpty(Application.Contents(key)))
	End Function
	
	' 得到某个键对应值
	Public Function [Get](key)
		key = getKey(key)		
		[Get] = Application.Contents(key)
	End Function
	
	' 添加或修改一个键值对
	Public Sub [Set](key,value)
		call Lock		
		key = getKey(key)
		if isDate(value) Then
			Application(key) = CStr(value)
		else 
			Application(key) = value
		End If
		call Unlock
	End Sub
	
	' 获取真正的键
	Public Function getKey( key )
		getKey = prefix & key
	End Function
	
	'锁定
	Public Sub Lock
		Application.lock
	End Sub
	
	' 解锁
	Public Sub Unlock
		Application.unlock
	End Sub
	
	Private Sub Class_Initialize
		prefix = POP_MVC.getConfig("APPLICATION_PREFIX")
	End Sub
	
	Private Sub Class_Terminate

	End Sub
End Class
%>